package com.itheima.demo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.stream.Stream;

@SuppressWarnings("all")
public class Demo_Stream001 {
    public static void main(String[] args) {
        //单列集合获取stream方法;
        method001();
        System.out.println("====================");
        //双列集合获取stream方法;
        method002();
        System.out.println("====================");
        //数组获取stream方式;
        method003();
        System.out.println("====================");
        //同种类型的多个数据;
        method004();
        System.out.println("====================");
    }

    private static void method004() {
        Stream.of(1, 2, 3, 4, 5).forEach(s -> System.out.println(s));
    }

    private static void method003() {
        int[] arr = {1, 2, 3, 4, 5};
        Arrays.stream(arr).forEach(s -> System.out.println(s));
    }

    private static void method002() {
        HashMap<String, Integer> map = new HashMap<>();
        map.put("zhangsan", 23);
        map.put("lisi    ", 24);
        map.put("wangwu  ", 25);
        map.put("zhaoliu ", 26);
        //第一种方式;
        map.keySet().stream().forEach(key -> System.out.println(map.get(key)));
        //第二种方式;
        map.entrySet().stream().forEach(entry -> System.out.println(entry));
    }

    private static void method001() {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "aaa", "bbb", "ccc");
        list.stream().forEach(s -> System.out.println(s));
    }
}
